package com.kqzz.common.api.response;

import org.slf4j.MDC;

import com.kqzz.common.utils.SystemContants;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * 统一响应结构Response对象
 * @author  lp_Administrator
 * @date    2017年11月17日 下午1:52:07
 * @version 1.0
 * com.kanq.zz.jsonBean
 */
@ApiModel(value = "统一响应结构Response对象")
public class Response {
	private static final String OK = "success";
    private static final String ERROR = "error";

    @ApiModelProperty(value = "返回编码1:成功,0:失败")
    private int errorNo;

    @ApiModelProperty(value = "返回信息内容")
    private String errorMsg;

    @ApiModelProperty(value = "返回链路追踪id")
    private String reqId;

	private String token;

	@ApiModelProperty(value = "返回对象")
    private Object response;

    public Response success() {
//        this.meta = new Meta(true, OK);
        this.errorNo = 1;
        this.errorMsg = OK;
        this.reqId = MDC.get(SystemContants.TRACE_ID);
        return this;
    }

    public Response success(Object response) {
//        this.meta = new Meta(true, OK);
        this.errorNo = 1;
        this.errorMsg = OK;
        this.response = response;
        this.reqId = MDC.get(SystemContants.TRACE_ID);
        return this;
    }

    /**
     * 返回追加token参数的请求结果
     * @param token
     * @param data
     * @return
     */
    public Response success_Token(String token,Object response) {
//        this.meta = new Meta(true, OK);
    	this.errorNo = 1;
        this.errorMsg = OK;
        this.token = token;
        this.response = response;
        this.reqId = MDC.get(SystemContants.TRACE_ID);
        return this;
    }

    public Response failure() {
//        this.meta = new Meta(false, ERROR);
        this.errorNo = 0;
        this.errorMsg = ERROR;
        this.reqId = MDC.get(SystemContants.TRACE_ID);
        return this;
    }

    public Response failure(String message) {
//        this.meta = new Meta(false, message);
        this.errorNo = 0;
        this.errorMsg = message;
        this.reqId = MDC.get(SystemContants.TRACE_ID);
        return this;
    }

    public Response logout() {
      this.errorNo = 9;
      this.errorMsg = ERROR;
      this.reqId = MDC.get(SystemContants.TRACE_ID);
      return this;
  }

  public Response logout(String message) {
      this.errorNo = 9;
      this.errorMsg = message;
      this.reqId = MDC.get(SystemContants.TRACE_ID);
      return this;
  }

    public Object getResponse() {
        return response;
    }

    public int getErrorNo() {
		return errorNo;
	}

	public String getErrorMsg() {
		return errorMsg;
	}

	public String getToken() {
		return token;
	}

	public String getReqId() {
		return reqId;
	}

	public void setReqId(String reqId) {
		this.reqId = reqId;
	}
}
